package com.lagou.service.impl;

import com.lagou.common.ServerResponse;
import com.lagou.mapper.IndustryMapper;
import com.lagou.service.IIndustryService;
import com.lagou.vo.SalaryCountVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class IIndustryServiceImpl implements IIndustryService {
    @Autowired
    private IndustryMapper mapper;

    @Override
    public ServerResponse<Map<String, Object>> top10AvgSalary() {
        //获取数据库数据；
        List<SalaryCountVo> results = mapper.getTop10AvgSalaryCity();

        //创建返回数据集
        Map<String, Object> resMap= new HashMap<>();
        List<String> names = new ArrayList<>();
        List<Double> counts = new ArrayList<>();

        resMap.put("names", names);
        resMap.put("count", counts);

        //迭代result
        for (SalaryCountVo result : results) {
            names.add(result.getNames());
            counts.add(result.getCount());
        }
        return ServerResponse.createBySuccessData(resMap);
        
    }
}
